package cn.yuanqiao.web.controller.archive.storeRoom;

import cn.yuanqiao.archive.appManager.domain.TenantSysDictData;
import cn.yuanqiao.archive.appManager.service.ITenantSysDictTypeService;
import cn.yuanqiao.archive.storeRoom.domain.Humiture;
import cn.yuanqiao.archive.storeRoom.domain.SafetyCheck;
import cn.yuanqiao.archive.storeRoom.service.ISafetyCheckService;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * SafetyCheckController
 * 
 * @author xy
 * @date 2023-06-15
 */
@Api
@RestController
@RequestMapping("/archive/safetyCheck")
public class SafetyCheckController extends BaseController
{
    @Autowired
    private ISafetyCheckService safetyCheckService;

    @Autowired
    private ITenantSysDictTypeService sysDictTypeService;

    /**
     * 查询SafetyCheck列表
     */


    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:DailySafety:list')")
    @GetMapping("/list")
    public TableDataInfo list(SafetyCheck safetyCheck)
    {
        startPage();
        List<SafetyCheck> list = safetyCheckService.selectSafetyCheckList(safetyCheck);
        return getDataTable(list);
    }

    /**
     * 导出SafetyCheck列表
     */


/*
    @PreAuthorize("@ss.hasPermi('storeroom:safetyCheck:export')")
*/
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:DailySafety:export')")
    @Log(title = "安全检查", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SafetyCheck safetyCheck)
    {
        List<SafetyCheck> list = safetyCheckService.selectSafetyCheckList(safetyCheck);


        for(int i=0;i<list.size();i++){
            SafetyCheck newSafetyCheck=list.get(i);
            String dictValue = null;
            List<TenantSysDictData> dictDataList = sysDictTypeService.selectDictDataByType("CHECKTYPE");  //WEATHER
            for (TenantSysDictData dict : dictDataList) {
                if (dict.getDictLabel().equals(newSafetyCheck.getCheckType().toString()) || dict.getDictValue().equals(newSafetyCheck.getCheckType().toString())) {  // 10年   D10
                    dictValue = dict.getDictLabel();
                    break;
                }
            }
            newSafetyCheck.setCheckLx(dictValue) ;
            list.set(i,newSafetyCheck);
        }
        ExcelUtil<SafetyCheck> util = new ExcelUtil<SafetyCheck>(SafetyCheck.class);
        util.exportExcel(response, list, "SafetyCheck数据");
    }

    /**
     * 获取SafetyCheck详细信息
     */


/*
    @PreAuthorize("@ss.hasPermi('storeroom:safetyCheck:query')")
*/
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:DailySafety:detail')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(safetyCheckService.selectSafetyCheckByID(id));
    }

    /**
     * 新增SafetyCheck
     */


/*
    @PreAuthorize("@ss.hasPermi('storeroom:safetyCheck:add')")
*/
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:DailySafety:add')")
    @Log(title = "安全检查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SafetyCheck safetyCheck)
    {
        return toAjax(safetyCheckService.insertSafetyCheck(safetyCheck));
    }

    /**
     * 修改SafetyCheck
     */


/*
    @PreAuthorize("@ss.hasPermi('storeroom:safetyCheck:edit')")
*/
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:DailySafety:edit')")
    @Log(title = "安全检查", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SafetyCheck safetyCheck)
    {
        return toAjax(safetyCheckService.updateSafetyCheck(safetyCheck));
    }

    /**
     * 删除SafetyCheck
     */


/*
    @PreAuthorize("@ss.hasPermi('storeroom:safetyCheck:remove')")
*/
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:DailySafety:delete')")
    @Log(title = "安全检查", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(safetyCheckService.deleteSafetyCheckByIds(ids));
    }


}
